//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
    components: {//动态扩充组件或组件路径
        //表单header、content、footer对应位置扩充的组件
        gridHeader:'',//{ template: "<div>扩展组xx件</div>" },
        gridBody: '',
        gridFooter: '',
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        modelHeader: '',
        modelBody: '',
        modelFooter: ''
    },
    buttons: {view: [], box:[],  detail:[]},//扩展的按钮
    methods: {//事件扩展
        getFormOption(field) {
            let option;
            this.editFormOptions.forEach(x => {
                x.forEach(item => {
                    if (item.field == field) {
                        option = item;
                    }
                })
            })
            return option;
        },
       onInit() {
        this.maxBtnLength = 6;
        this.columns.push({
            title: '操作',
            fixed: 'right',
            width: 140,
            render: (h, { row, column, index }) => {
                return h(
                    "div", { style: {} }, [
                        h(
                            "a", {
                                props: {},
                                style: {},
                                on: {
                                    click: (e) => {
                                        //this.$Message.info(row.accountsReceivable);
                                        // e.stopPropagation()
                                        //console.log(this.$refs.gridHeader)
                                        this.linkData(row);
                                    }
                                }
                            },
                            "编辑"
                        ),
                        
                    ])
            }
        })
        let isEDIT = this.currentAction == this.const.EDIT;
       
            this.$store.getters.data().reportPrice = this;
        this.editFormFileds.mall_category = [];
        var selectOption = this.getFormOption('mall_category');
        selectOption.type = "cascader";
         // 设置任意节点都能选中(默认只能选中最后一个节点)
        selectOption.changeOnSelect = false;
           // 格式化数据显示(只显示当前选中的最后一个节点)，默认会显示所有节点的数据
            selectOption.formatter = nodeArr => {
              if (!nodeArr.length) {
                return "";
              }
              return nodeArr[nodeArr.length - 1];
            };
        //初始一个空的数据源(必须)
        selectOption.data=[];
        selectOption.onChange = (val, item) => {  
        let productname="";
        let prodctcode="";
        for(let i=item.length-1;i>=0;i--){
          if(i==item.length-1){productname+=item[i].label;prodctcode+=item[i].value};
          if(i==0){productname+=item[i].label;prodctcode+=item[i].value};
        }
        if(this.editFormFileds.mall_category==''){
          this.editFormFileds.mall_category=productname;
          this.editFormFields.typeName= productname;
          this.editFormFileds.typeCode=prodctcode;}
          //this.getcolumn(val);
          //this.$set(selectOption, "disabled", true);
          }  
        
       },
       rowClick({ row, column, event }) { //查询界面table点击行选中当前行
        //console.log(row,column,event);
       
        this.$refs.table.$refs.table.toggleRowSelection(row);
        
        return true;
       },
       modelOpenBefore(){
        // let isEDIT = this.currentAction == this.const.EDIT;
        // if(!isEDIT){
            var selectOption = this.getFormOption('mall_category');
            selectOption.data=[];
              //从后台接口返回数据源,格式见iview组件result(建议在modelOpenBefore方法中设置数据源)
                this.http.post("api/producttypes/GetProtypeList4").then(result=>{
                  result.result.forEach(item=>{
                      selectOption.data.push(item)
                  })
              })
        //}
        
      },
    //   getDate(p){
    //     this.http.post("api/producttypes/GetDateList?id="+p,{ },true).then(reslut=>{
    //         this.tabledata=reslut.data
    //     })
    //    },
      modelOpenAfter() {
        this.boxOptions.height = document.documentElement.clientHeight * 0.8;
        let isEDIT = this.currentAction == this.const.EDIT;
        var mall_categoryOption = this.getFormOption("mall_category");
        var typeNameOption = this.getFormOption("typeName");
        if(!isEDIT)
        {
          this.$set(mall_categoryOption, "hidden", false)
          
        }else{
          this.$set(mall_categoryOption, "hidden", true)
          this.editFormFileds.mall_category=[];
          
        }
        if(isEDIT){
          this.$set(typeNameOption, "hidden", false)

        }else{
          this.$set(typeNameOption, "hidden", true)
          this.editFormFileds.typeName=[];
        }
        //设置房形名称编码根据房型的值而变化
        var selectOption = this.getFormOption('mall_name');  
        if(!isEDIT) {
            selectOption.onInput = (val) => {    
            this.editFormFields.mall_code=this.base.chineseToPinYin(val);
            }
        } 
        var Code = this.getFormOption('mall_code');
        this.$set(Code, "disabled", true)
       
        // if(isEDIT){
        //     this.getDate(this.currentRow);
        // }
            //点击弹出框后，如果是编辑状态，禁止编辑帐号，如果新建状态，将帐号字段设置为可编辑
            this.editFormOptions.forEach(item => {
                item.forEach(x => {
                        //如果是编辑帐号设置为只读
                        if (x.field == "typeCode") {
                            //disabled是editFormOptions的动态属性，这里只能通过this.$set修改值
                            this.$set(x, "disabled", true)
                        }
                        if(x.field == "typeName"){
                            this.$set(x,"disabled",true)
                        }
                        if (x.field == "mall_category") {
                          
                          //disabled是editFormOptions的动态属性，这里只能通过this.$set修改值
                          if(!isEDIT) {
                            x.onInput = (val) => {  
                              //console.log(this.base.chineseToPinYin(val))
                              this.editFormFileds.typeCode=this.base.chineseToPinYin(val)
                            }
                        } 
                      }
                        
                    })
            })
        
            //获取当前弹出框是新建还是编辑状态
        },
    }
};
export default extension;